package com.niuwa.p2p.service.impl.fund;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.dao.fund.AccountBankcardDao;
import com.niuwa.p2p.dao.fund.CustAccountDao;
import com.niuwa.p2p.entity.fund.AccountBankcard;
import com.niuwa.p2p.entity.fund.AccountBankcardKey;
import com.niuwa.p2p.entity.fund.CustAccount;
import com.niuwa.p2p.service.fund.IAccountBankcardService;

@Service
public class AccountBankcardServiceImpl  implements IAccountBankcardService{
    
	@Autowired
	private AccountBankcardDao  accountBankcardDao;
	
	@Autowired
	private CustAccountDao custAccoundDao;
	
	
	/**
     * 资金账户绑定的银行卡【web】 
     * @param paramMap [acctNo 账户号、status 银行卡状态]
     * @return
     */
	@Override
	public AccountBankcard selectBankCardBySelective(Map<String, Object> paramMap){
		return accountBankcardDao.selectBankCardBySelective(paramMap);
	}




	@Override
	public int bindBankCard(Map<String, Object> paramMap) {
		int result=0;
		try {
			String custId=paramMap.get("custId").toString();
			String acctNo=paramMap.get("acctNo").toString();
			CustAccount account=custAccoundDao.getAccountInfoByCustId(Long.valueOf(custId));
			if (null!=account && acctNo.equals(account.getAccountNo())) {
				AccountBankcard bankcard=new AccountBankcard();
				bankcard.setAcctNo(acctNo);//资金账户号
				bankcard.setCardNo(paramMap.get("cardNo").toString());
				bankcard.setBankCode(paramMap.get("bankCode").toString());
				bankcard.setBankName(paramMap.get("bankName").toString());
				bankcard.setBindTime(new Date());//绑定时间
				bankcard.setStatus(paramMap.get("status").toString());
				result=accountBankcardDao.insertSelective(bankcard);
			}
		} catch (Exception e) {
			// TODO: LOG
			e.printStackTrace();
		}
		return result;
	}




	@Override
	public int deleteBindCard(AccountBankcardKey bankcard) {
		return accountBankcardDao.deleteByPrimaryKey(bankcard);
	}
}
